{% extends"@Fortend/layout.html.twig" %}

{% block title %}{% endblock %}

{% block content %}
    {#{{ dump(data) }}#}
    {% include '@Fortend/Public/header.html.twig' %}

    <div class="layui-container fly-marginTop">
        <div class="fly-panel" pad20 style="padding-top: 5px;">
            <!--<div class="fly-none">没有权限</div>-->
            <div class="layui-form layui-form-pane">
                <div class="layui-tab layui-tab-brief" lay-filter="user">
                    <ul class="layui-tab-title">
                        <li class="layui-this">发表新帖<!-- 编辑帖子 --></li>
                    </ul>
                    <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                        <div class="layui-tab-item layui-show">
                            <form action="" method="post">
                                <div class="layui-row layui-col-space15 layui-form-item">
                                    <div class="layui-col-md3">
                                        <label class="layui-form-label">所在专栏</label>
                                        <div class="layui-input-block">
                                            <select class="select-classify" lay-verify="required" name="class" lay-filter="column">
                                                <option></option>
                                                {% for item in data.article_type %}
                                                <option value="{{ item.id }}">{{ item.name }}</option>
                                                {% endfor %}
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-col-md9">
                                        <label for="L_title" class="layui-form-label">标题</label>
                                        <div class="layui-input-block">
                                            <input type="text" id="L_title" name="title" required lay-verify="required" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <div class="layui-input-block">
                                        <textarea id="L_content" name="content" required lay-verify="required" placeholder="详细描述" class="layui-textarea fly-editor" style="height: 260px;"></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <button class="layui-btn" lay-filter="form-submit" lay-submit>立即发布</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {% include '@Fortend/Public/footer.html.twig' %}
{% endblock %}

{% block js %}
    <script>
        var upload_url = '{{ path('api_public_upload_image') }}';

        layui.use('form', function(){
            var form = layui.form;

            //监听提交
            form.on('submit(form-submit)', function(data) {
                //  获取选中的文本
                data.field.class_name = $('.select-classify option:selected').text();

                $.ajax({
                    url: '{{ path('api_post_opera') }}',
                    data: data.field,
                    type: 'POST',
                    success: function (res) {
                        layer.msg(res.message, {time: '1000'});
                        if (res.errorCode === 0) {
                            setTimeout(function () {
                                location.href = '{{ path('fortend_homepage') }}';
                            }, 1000)
                        }
                    }
                });

                return false;
            });
        });
    </script>
{% endblock %}